public class Computer {
    private final String vendor;
    private final String name;

    private Processor processor;
    private Memory memory;
    private Storage storage;
    private Screen screen;
    private Keyboard keyboard;

    public Computer(String vendor, String name) {
        this.vendor = vendor;
        this.name = name;
    }

    public String getVendor() {
        return vendor;
    }

    public String getName() {
        return name;
    }

    public Processor getProcessor() {
        return processor;
    }

    public Memory getMemory() {
        return memory;
    }

    public Storage getStorage() {
        return storage;
    }

    public Screen getScreen() {
        return screen;
    }

    public Keyboard getKeyboard() {
        return keyboard;
    }

    public void setProcessor(Processor processor) {
        this.processor = processor;
    }

    public void setMemory(Memory memory) {
        this.memory = memory;
    }

    public void setStorage(Storage storage) {
        this.storage = storage;
    }

    public void setScreen(Screen screen) {
        this.screen = screen;
    }

    public void setKeyboard(Keyboard keyboard) {
        this.keyboard = keyboard;
    }

    public double getWeight() {
        double weight = 0;

        if (processor != null) weight = weight + processor.getWeight();
        if (memory != null) weight = weight + memory.getWeight();
        if (storage != null) weight = weight + storage.getWeight();
        if (screen != null) weight = weight + screen.getWeight();
        if (keyboard != null) weight = weight + keyboard.getWeight();

        return weight;
    }

    public String toString() {
        String string = "Компьютер " + getVendor() + " " + getName();

        if (processor != null) string = string + "\n" + processor;
        if (memory != null) string = string + "\n" + memory;
        if (storage != null) string = string + "\n" + storage;
        if (screen != null) string = string + "\n" + screen;
        if (keyboard != null) string = string + "\n" + keyboard;

        return string;
    }
}
